﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Entity.Core
{
    /// <summary>
    /// 获取或者设置生成代码的版本号。
    /// </summary>
    public class CodeVersion
    {
        XmlDocument doc;

        public CodeVersion()
        {
            doc = new XmlDocument();
            doc.Load("Config.xml");
        }
        /// <summary>
        /// 设置版本号
        /// </summary>
        /// <param name="version"></param>
        /// <returns></returns>
        public bool WriteVersion(string version)
        {
            XmlNodeList nodeList = doc.GetElementsByTagName("CodeVersion");
            nodeList[0].InnerText = version;
            try
            {
                doc.Save("Config.xml");
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// 读取版本号
        /// </summary>
        /// <param name="version"></param>
        /// <returns></returns>
        public string ReadVersion()
        {
            XmlNodeList nodeList = doc.GetElementsByTagName("CodeVersion");
            return nodeList[0].InnerText;
        }

        /// <summary>
        /// 是否使用的是.net2.0；
        /// </summary>
        public bool IsVersion2
        {
            get
            {
                if (ReadVersion() == "2.0")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
    }
}
